# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod
import math

class Commission(object):
    """
    手续费
    """
    __metaclass__ = ABCMeta

    @abstractmethod
    def get_commission(self):
        raise NotImplementedError("Should implemet get_commission()")


# 零手续费
class ZeroCommission(Commission):
    def get_commission(self):
        return 0.0

    def __repr__(self):
        return "{class_name}".format(class_name=self.__class__.__name__)

# 按股计算的手续费
class PerShareCommission(Commission):
    def __init__(self, rate=0.001, min_comm=0.0):
        self.rate_per_share = rate
        self.min_comm = min_comm

    def get_commission(self, quantity):
        return max(math.ceil(quantity * self.rate_per_share), self.min_comm)

    def __repr__(self):
        return "{class_name}(rate_per_share={rate}, min_commission={min_comm})".format(
            class_name=self.__class__.__name__, rate=self.rate_per_share, min_comm=self.min_comm)

# 按钱计算的手续费
class PerMoneyCommission(Commission):
    def __init__(self, rate=1.5e-4, min_comm=0.0):
        self.rate_per_money = float(rate)
        self.min_comm = float(min_comm)

    def get_commission(self, full_cost):
        return max(full_cost * self.rate_per_money, self.min_comm)

    def __repr__(self):
        return "{class_name}(rate_per_money={rate}, min_commission={min_comm})".format(
            class_name=self.__class__.__name__, rate=self.rate_per_money, min_comm=self.min_comm)

# 按照交易比数计算的手续费
class PerTradeCommission(Commission):
    pass